﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DataControl;
using System.Data;
using System.Text;

namespace ATW.MT.BUS
{
    public class bus_C_Size
    {
        DataAccess da = null;
        public bus_C_Size()
        {
            da = new DataAccess();
        }
        #region 方法
        /// <summary>
        /// 口径分页查询
        /// </summary>
        /// <param name="name"></param>
        /// <param name="page"></param>
        /// <param name="pagesize"></param>
        /// <returns></returns>
        public DataTable SizePagerQuery(string name, int page, int pagesize)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(@"select top 100 percent * from C_Size where 1=1 ");
            if (!String.IsNullOrEmpty(name))
            {
                sql.Append(" and size_code_C like '%" + name + "%' or size_code_s like '%" + name + "%'");
            }
            sql.Append("order by Size_Code_C,Size_Code_S");
            return da.PageSize(sql.ToString(), page, pagesize, "SID", "create_time desc");
        }
        public DataTable SizeQuery(string ProductionID)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select S.* from T_Production_Size PS left join C_Size S 
                                on PS.SID=S.SID where ProductionID='{0}'",ProductionID);
            return da.ExecuteDataTable(sql.ToString());
        }
        /// <summary>
        /// 新增口径
        /// </summary>
        /// <param name="code_c">公制口径单位</param>
        /// <param name="code_s">ANSI制</param>
        /// <returns></returns>
        public int SizeAdd(string code_c, string code_s)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into C_Size(Size_Code_C,Size_Code_S) values('{0}','{1}')", code_c, code_s);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 新增口径
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        public int SizeAdd(string code_c, string code_s, string rate)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"insert into C_Size(Size_Code_C,Size_Code_S,Size_rate) values('{0}','{1}','{2}')", code_c, code_s, rate);
            return da.ExcuteNoQuery(sql.ToString());
        }
        /// <summary>
        /// 口径是否存在
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <returns></returns>
        public bool isSizeExist(string code_c, string code_s)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"select * from c_size where Size_Code_C='{0}' and Size_Code_S='{1}'", code_c, code_s);
            DataTable dt = da.ExecuteDataTable(sql.ToString());
            if (dt != null && dt.Rows.Count > 0)
            {
                return true;
            }
            return false;
        }
        /// <summary>
        /// 修改口径
        /// </summary>
        /// <param name="code_c"></param>
        /// <param name="code_s"></param>
        /// <param name="sid"></param>
        /// <returns></returns>
        public int SizeEdit(string code_c, string code_s, string rate, string sid)
        {
            StringBuilder sql = new StringBuilder();
            sql.AppendFormat(@"update C_size set size_code_c='{0}',size_code_s='{1}',Size_rate='{3}' where sid='{2}'", code_c, code_s, sid, rate);
            return da.ExcuteNoQuery(sql.ToString());
        }
        #endregion
    }
}